﻿



$.MGJ.TransientState = [];

(function () {
    var _this = $.MGJ.TransientState;
    $.extend($.MGJ.TransientState, {
        // 申请退货
        Dialog_PendingAllotObj: null,
        Dialog_PendingAllot: function (obj) {
            
            var formCode = $(obj).attr("FormCode");
            var ID = $(obj).attr("ID");
            var type = $(obj).attr("Type");
            if (obj.text == "查看") {

                this.Dialog_PendingAllotObj = $.L.dialog({
                    url: ACTION_URL("PendingAllot", "FleeGoods") + "?formCode=" + formCode + "&type=" + type,
                    title: obj.text,
                    width: 800,
                    height:400,
                    buttons: {
                        "button_cancel": {
                            type: 'default',
                            text: '返回',
                            click: 'MODALMISS'
                        }
                    }
                })

            }
            else if (type == 1) {
                this.Dialog_PendingAllotObj = $.L.dialog({
                    url: ACTION_URL("PendingAllot", "FleeGoods") + "?formCode=" + formCode + "&type=" + type,
                    title: obj.text,
                    width: 800,
                    height: 400,
                    buttons: {
                        "button_save": {
                            type: 'primary',
                            text: '同意',
                            click: function () {
                                if ($("WarehouseId").val() != "") {
                                    $.MGJ.TransientState.Dialog_Agree(ID)
                                } else {
                                    $.L.msgError("收货仓库不能为空")
                                }
                            }
                        },
                        "button_refuse": {
                            type: 'default',
                            text: '拒绝',
                            click: function () {

                                $.L.msgConfirm("是否拒绝？", function () {
                                    $.MGJ.TransientState.Ajax_Disgree(ID);
                                })
                            }
                        },
                    }
                })
            }
            else {
                this.Dialog_PendingAllotObj = $.L.dialog({
                    url: ACTION_URL("PendingAllot", "FleeGoods") + "?formCode=" + formCode + "&type=" + type,
                    title: obj.text,
                    width: 800,
                    height: 400,
                    buttons: {
                        "button_toup": {
                            type: 'primary',
                            text: '退给上级处理',
                            click: function () {
                                $.MGJ.TransientState.Ajax_BackSuperior(ID);
                            }
                        },
                        "button_save": {
                            type: 'primary',
                            text: '同意',
                            click: function () {
                                if ($("WarehouseId").val() != "") {
                                    $.MGJ.TransientState.Dialog_Agree(ID)
                                } else {
                                    $.L.msgError("收货仓库不能为空")
                                }
                            }
                        },
                        "button_refuse": {
                            type: 'default',
                            text: '拒绝',
                            click: function () {
                                
                                $.L.msgConfirm("是否拒绝？", function () {
                                    $.MGJ.TransientState.Ajax_Disgree(ID);
                                })
                            }
                        },
                    }
                })
            }
        },
        //点击同意按钮
        Dialog_AgreeObj: null,
        Dialog_Agree: function (obj) {
            var type = $('#Type').val();
            var formCode = $('#FormCode').val();
            var ID = obj;
            if(type !=1)//退货
            {
               
                _this.Ajax_THAgree(ID);
            }
            else {
                _this.Dialog_PendingAllotObj.close();
                this.Dialog_AgreeObj = $.L.dialog({
                    url: ACTION_URL("Agree", "FleeGoods"),
                    title: "调货处理",
                    width: 700,
                    height: 'auto',
                    buttons: {
                        "button_save": {
                            type: 'primary',
                            text: '确认',
                            click: function () {
                                _this.Ajax_DHAgree(formCode+','+ID);
                                _this.Dialog_AgreeObj.close();
                            }
                        },
                        "button_cancel": {
                            type: 'default',
                            text: '取消',
                            click: 'MODALMISS'
                        }
                    },
                });
            }
        }
    });
})(jQuery);
(function () {
    var _this = $.MGJ.TransientState;
    $.extend($.MGJ.TransientState, {
        //分页查询
        Ajax_PageList: function (pageIndex) {
            window.SearchKey = removeSpace($("#Key").val());
            $.L.ajaxHandle({
                url: ACTION_URL("ProcessPageList", "FleeGoods"),
                data: {
                    key: window.SearchKey,
                    pageIndex: pageIndex,
                    pageSize: 10
                },
                success: function (response) {
                    var data = response.PageData;
                    $("#tableList").L_bindingDataList(response);
                    for (var i = 0; i < data.length; i++) {             
                        if (data[i].Status == 0) {
                            //show待处理
                            $(".look").eq(i).hide();
                        } else {
                            //show查看
                            $(".chuli").eq(i).hide();
                        }
                    }
                }  
            });
        },

        Ajax_THAgree: function (obj) {
            var ID = obj;
            $.L.ajaxHandle({
                url: ACTION_URL("THAgree", "FleeGoods"),
                data: { formCode: $("#FormCode").val(), warehouseId: $("#WarehouseId").val(), id: ID },
                success: function (r) {
                    if (r <= 0) {
                        $.L.msgError("审核失败！");
                    }
                    else {
                        $.L.msgSuccess("审核成功！");
                        _this.Ajax_PageList(1);
                        _this.Dialog_PendingAllotObj.close();
                    }
                   
                },

            })
        },
        Ajax_DHAgree: function (obj) {
           
            var SaleAreaId = $("#SaleAreaId").val();
            var Distributor = $("#Distributor").val();
            var data = obj.split(',');
            $.L.ajaxHandle({
                url: ACTION_URL("DHAgree", "FleeGoods"),
                data: { formCode: data[0], saleAreaId: SaleAreaId, distributor: Distributor, id: data[1] },
                success: function (r) {
                    if (r <= 0) {
                        $.L.msgWarning("审核失败！");
                    }

                    else {
                        $.L.msgSuccess("审核成功！");
                        _this.Ajax_PageList(1);
                        _this.Dialog_PendingAllotObj.close();
                    }
                   
                }
            });
        },
        //拒绝
        Ajax_Disgree: function (obj) {
            var Type = $("#Type").val();
            var FormCode = $("#FormCode").val();
            $.L.ajaxHandle({
                url: ACTION_URL("Disgree", "FleeGoods"),
                data: { formCode: FormCode, type: Type, id: obj },
                success: function (r) {
                    if (r <= 0) $.L.msgError("退回失败！");

                    else {
                        $.L.msgSuccess("退回中！");
                        _this.Ajax_PageList(1);
                        _this.Dialog_PendingAllotObj.close();
                    }
                }
            });
        },
        //返回给上级
        Ajax_BackSuperior: function (obj) {
            var ID = obj;//处理状态的ID
            var FormCode = $("#FormCode").val();
            $.L.ajaxHandle({
                url: ACTION_URL("BackSuperior", "FleeGoods"),
                data: { formCode: FormCode, id: ID },
                type:'post',
                success: function (r) {
                    if (r==-2) {
                        $.L.msgError("已是最高级别！");
                    }
                    else if (r<=0) $.L.msgError("操作失败！");
                    else {
                        $.L.msgSuccess("操作正在处理！");
                        _this.Ajax_PageList(1);
                        _this.Dialog_PendingAllotObj.close();
                    }
                }
            });
        },
    });
})(jQuery);
(function () {
    var _this = $.MGJ.TransientState;
    $.extend($.MGJ.TransientState, {


    });
})(jQuery);
